﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Ue.Qcdz.Domain.Shops;

namespace Ue.Qcdz.Repositories.Shops
{
    public class ShopDataQueryWhereClause : Ue.Infrastructure.RepositoryFramework.Repository.IWhereClause
    {
        private IShopDataQuery shopDataQuery;

        public ShopDataQueryWhereClause(IShopDataQuery dataQuery)
        {
            this.shopDataQuery = dataQuery;
        }
        #region IWhereClause 成员

        public string Clause
        {
            get
            {
                string whereClause = "1=1";
                if (!string.IsNullOrEmpty(this.shopDataQuery.Name))
                    whereClause += string.Format(" and {0} like '%{1}%'", ShopFactory.FieldNames.Name, shopDataQuery.Name);
                if (this.shopDataQuery.IsTop)
                    whereClause += string.Format(" and {0} = @{0}", ShopFactory.FieldNames.IsTop);
                if (this.shopDataQuery.Status)
                    whereClause += string.Format(" and {0} = {1}", ShopFactory.FieldNames.Status, 1);
                return whereClause;
            }
        }

        public System.Data.IDataParameter[] Parameters
        {
            get
            {
                return new IDataParameter[] {                 
                    SqlServerDriver.Instance.BuildParameter(ShopFactory.FieldNames.IsTop, this.shopDataQuery.IsTop)
               
                };



            }
        }

        #endregion
    }
}
